/*
 * Alberto Ruiz-Larrea Guillén...11383
 * Erdi Dogruel..................14955
 * Marcos Pérez Martín...........10324
 */

package com.example.database;

import android.annotation.SuppressLint;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.AsyncTask;
import android.widget.TextView;

import com.example.androball_manager.FirstMenuActivity;

//This class gets your gameday
public class GetYourGameDay extends AsyncTask<OpenDB, Integer, Integer> {

	TextView text;
	int team_int;

	public GetYourGameDay(TextView t) {
		text = t;
	}

	@SuppressLint("UseValueOf")
	@Override
	protected Integer doInBackground(OpenDB... params) {
		OpenDB db = params[0];
		SQLiteDatabase watch = db.getReadableDatabase();
		String[] columns = { OpenDB.id, OpenDB.game_home, OpenDB.game_away,
				OpenDB.score_home, OpenDB.score_away, OpenDB.gameday };

		Cursor cursor = watch.query(OpenDB.table3, columns, null, null, null,
				null, null);
		cursor.moveToFirst();

		while (!cursor.isAfterLast() && cursor.getInt(3) != -1) {
			cursor.moveToNext();
		}
		int res = cursor.getInt(5);
		cursor.close();

		return res;
	}

	@Override
	protected void onPostExecute(Integer result) {
		FirstMenuActivity.gameday = result;
	}
}